package com.yugao.fintech.vctgone.web.util;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import com.yugao.fintech.vctgone.web.enums.ResponseStatusEnum;

import java.time.LocalDateTime;

/**
 * response data
 */
@Data
public class ResultVO<T> {
    private String code;

    private String msg;

    private Boolean success;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime time = LocalDateTime.now();

    private T data;

    private ResultVO() {
    }

    public static <T> ResultVO<T> success() {
        return success(ResponseStatusEnum.OK.getCode(), ResponseStatusEnum.OK.getMsg(), null);
    }

    public static <T> ResultVO<T> success(T data) {
        return success(ResponseStatusEnum.OK.getCode(), ResponseStatusEnum.OK.getMsg(), data);
    }

    public static <T> ResultVO<T> success(String code, String msg, T data) {
        return success(code, msg, true, data);
    }

    public static <T> ResultVO<T> error() {
        return success(ResponseStatusEnum.SYS_ERROR.getCode(), ResponseStatusEnum.SYS_ERROR.getMsg(), false, null);
    }

    public static <T> ResultVO<T> error(String msg) {
        return success(ResponseStatusEnum.SYS_ERROR.getCode(), msg, false, null);
    }

    public static <T> ResultVO<T> error(String code, String msg) {
        return success(code, msg, false, null);
    }

    public static <T> ResultVO<T> error(ResponseStatusEnum status) {
        return success(status.getCode(), status.getMsg(), false, null);
    }

    public static <T> ResultVO<T> error(ResponseStatusEnum status, String msg) {
        return success(status.getCode(), msg, false, null);
    }

    public static <T> ResultVO<T> success(String code, String msg, Boolean success, T data) {
        ResultVO<T> rd = new ResultVO<>();
        rd.code = code;
        rd.msg = msg;
        rd.success = success;
        rd.data = data;
        return rd;
    }
}